package com.ycl.bookstore.controller;

import com.ycl.bookstore.DTO.LoginFormDTO;
import com.ycl.bookstore.common.Result;
import com.ycl.bookstore.service.UserService;
import com.ycl.bookstore.utils.MyThreadLocal;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;


@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Resource
    private UserService userService;

    /**
     * 登录功能
     * @param loginFormDTO
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginFormDTO loginFormDTO){
        //用户登录验证
        return userService.login(loginFormDTO);
    }

    /**
     * 获取用户信息
     * @param token
     * @return
     */
    @GetMapping("/info")
    public Result info(@RequestParam("token") String token){
        return userService.info(token);
    }

    /**
     * 退出功能
     * @return
     */
    @PostMapping("/logout")
    public Result logout(){
        //将用户移除
        MyThreadLocal.removeUser();
        return Result.success();
    }

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @PostMapping("/code")
    public Result sendCode(@RequestParam(value = "phone") String phone){
        return userService.sendCode(phone);
    }

    /**
     * 统计用户的签到次数
     */
    @GetMapping("/signCount")
    public Result signCount(){
        return userService.signCount();
    }

    @PostMapping("/sign")
    public Result sign(){
        return userService.sign();
    }

    @GetMapping("/isSign")
    public Result isSign(){
        return userService.isSign();
    }

    @GetMapping("/hasCoupon")
    public Result hasCoupon(){
        return userService.hasCoupon();
    }

}
